package com.work.dao.impl;

import com.work.bean.HwStuAttach;
import com.work.dao.BaseDao;
import com.work.dao.HwStuAttachDao;

import java.util.List;

public class HwStuAttachDaoImpl extends BaseDao implements HwStuAttachDao {
    public List<HwStuAttach> queryHwStuAttach() {
        String sql = "SELECT * FROM t_hw_stu_attach  ";
        return  queryForList(HwStuAttach.class,sql);
    }

    public HwStuAttach queryHwStuAttachById(Integer id) {
        String sql = "SELECT * FROM t_hw_stu_attach WHERE id = ? ";
        return  queryForOne(HwStuAttach.class,sql,id);
    }

    @Override
    public HwStuAttach queryHwStuAttachByHwStuId(Integer hw_stu_attach_id) {
        String sql = "SELECT * FROM t_hw_stu_attach WHERE hw_stu_id = ? ";
        return  queryForOne(HwStuAttach.class,sql,hw_stu_attach_id);
    }

    public int saveHwStuAttach(HwStuAttach hwStuAttach) {
        String sql = "INSERT INTO `t_hw_stu_attach` (`hw_stu_id`, `type`, `url`) VALUES (?, ?, ?)";
        return update(sql,hwStuAttach.getHwStuId(),hwStuAttach.getType(),hwStuAttach.getUrl());
    }

    public int updateHwStuAttach(HwStuAttach hwStuAttach) {
        String sql = "UPDATE t_hw_stu_attach SET `hw_stu_id `=?,type`=?,`url`=? WHERE `id` = ?";
        return update(sql,hwStuAttach.getHwStuId(),hwStuAttach.getType(),hwStuAttach.getUrl(),hwStuAttach.getId());
    }

    public int deleteHwStuAttach(Integer id) {
        String sql = "DELETE FROM `t_hw_stu_attach` WHERE `id` = ?";
        return update(sql, id);
    }

    public int deleteHwStuAttach1(Integer hw_stu_id) {
        String sql = "DELETE FROM `t_hw_stu_attach` WHERE `hw_stu_id` = ?";
        return update(sql, hw_stu_id);
    }
}
